package ee.subjects.frontend.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class EventFinder {
	private HttpServletRequest request;
	private HttpServletResponse response;
	
	public EventFinder(HttpServletRequest request, HttpServletResponse response){
		this.request=request;
		this.response=response;
	}

	public String find(String mode) throws ServletException, IOException  {

		String event = "undefined";
		try {
			
			if(mode.equals("person")){
				if (request.getParameter("event") != null){
					String requestEvent = request.getParameter("event");
					
					if (requestEvent.equals("insert_person")){
						event = "insert_person";
					}
					if(requestEvent.equals("save_person")){
						event = "save_person";
					}
					if(requestEvent.equals("edit_person")){
						event = "edit_person";
					}
					if(requestEvent.equals("ajax_person")){
						event = "ajax_person";
					}
					if(requestEvent.equals("allPersons")){
						event = "allPersons";
					}
				}
			}else if(mode.equals("enterprise")){
				if (request.getParameter("event") != null){
					String requestEvent = request.getParameter("event");
					
					if (requestEvent.equals("insert_enterprise")){
						event = "insert_enterprise";
					}
					if(requestEvent.equals("save_enterprise")){
						event = "save_enterprise";
					}
					if(requestEvent.equals("edit_enterprise")){
						event = "edit_enterprise";
					}
					if(requestEvent.equals("allEnterprises")){
						event = "allEnterprises";
					}
				}
			}else if(mode.equals("employee")){
				if (request.getParameter("event") != null){
					String requestEvent = request.getParameter("event");
					
					if (requestEvent.equals("insert_employee")){
						event = "insert_employee";
					}
					if(requestEvent.equals("enterprise_list_for_employees")){
						event = "enterprise_list_for_employees";	
					}
					if(requestEvent.equals("ajax_employee")){
						event = "ajax_employee";
					}
					if(requestEvent.equals("roles")){
						event = "roles";
					}
				}
			}
			
			
			
		} catch (Exception ex) {
			//TODO Logimine
			//MyLogger.Log("MenuControllerFactory.service():",ex.getMessage());
		}
		return event;
	}

}
